<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>amis admin</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <link
            rel="stylesheet"
            title="default"
            href="sdk.css"
    />
    <link
            rel="stylesheet"
            title="default"
            href="helper.css"
    />

    <script src="sdk.js"></script>
    <script src="index.js"></script>

    <link rel="stylesheet" href="iconfont.css" />
    <script src="https://unpkg.com/history@4.10.1
/umd/history.js"></script>
    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
        .amis-scope .cxd-Layout-footer {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            z-index: 0;
        }
        .amis-scope .cxd-Layout-content{padding-bottom:6rem;}
        .cxd-AppBcn{display:none}
        .cxd-Panel-heading{display:none}
        .amis-scope .cxd-Layout-headerBar{display:block;padding: 0.65rem;}
        .amis-scope .cxd-Layout-brandBar{display:none}
        .cxd-myClass, .myClass{fill:red}
        .cxd-AppFoldBtn{display:none}
        .app-wrapper { overflow: -moz-scrollbars-none; }
        .app-wrapper { -ms-overflow-style: none; }
        .app-wrapper::-webkit-scrollbar { width: 0 !important }
        .amis-scope .cxd-Layout-headerBar{padding:0px;}
        .amis-scope .cxd-Layout-footer{z-index:51}
    </style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script>







    var app = {
        "type": "app",
        "name":"topapp",
        "brandName": "应用名称",
        "footer":{
            "columnNum":4,
            "name":"zhazha",
            "type": "grid-nav",
            "source": "${items}",
            "hiddenOn": "headindex === 'back'"
        },
        "header": {
            "type": "container",
            "style": {
                "height": "100%"
            },
            "body":{
                "type": "service",
                "className":"bg-white",
                "body": [{
                    "type":"tpl",
                    "tpl":"<div class=\"flex p-4 justify-between\"><div>顶部区域左侧</div><div>顶部区域右侧</div></div>",
                    "hiddenOn": "headindex != 1"
                },{
                    "type":"tpl",
                    "tpl":"<div class=\"flex p-4 justify-between\"><div>顶部区域1侧</div><div>顶部区域2侧</div></div>",
                    "hiddenOn": "headindex != 2"
                },{
                    "type":"tpl",
                    "tpl":"<div class=\"flex p-4 justify-between bg-white h-full\"><div>&nbsp;</div></div>",
                    "hiddenOn": "headindex != 'white'"
                },{
                    "type":"tpl",
                    "tpl":"<div class=\"hbox h-full border-0 p-1.5 \">\n" +
                        "  <div class=\"col border-0 wrapper-sm \" onclick='history.goBack()'  ><i  class=\"fa fa-angle-left \"></i></div>\n" +
                        "  <div class=\"col border-0 wrapper-sm text-center\">  ${window:document[title]}</div>\n" +
                        "  <div class=\"col border-0 wrapper-sm \"></div>\n" +
                        "</div> ",
                    "hiddenOn": "headindex != 'back'"
                }]
            }

        },
        "pages": [

            {
                label: "示例",

                children: [
                    {
                        label: "页面A",
                        url: "pageA",
                        schema: {
                            type: "page",
                            title: "页面A",
                            body: "页面A"
                        },
                        children: [
                            {
                                label: "页面A-1",
                                url: "1",
                                schema: {
                                    "type": "form",
                                    "title": "优惠券生成",
                                    "body": [
                                        {
                                            "label": "名称",
                                            "type": "input-text",
                                            "name": "text"
                                        },
                                        {
                                            "type": "select",
                                            "label": "封面选择",
                                            "name": "select",
                                            "options": [
                                                {
                                                    "label": "${token}",
                                                    "value": "${token}"
                                                },
                                                {
                                                    "label": "选项B",
                                                    "value": "B"
                                                }
                                            ]
                                        },
                                        {
                                            "type": "input-image",
                                            "label": "图片上传",
                                            "name": "image",
                                            "imageClassName": "r w-full",
                                            "mode": ""
                                        },
                                        {
                                            "type": "input-range",
                                            "label": "折扣力度",
                                            "name": "range"
                                        },
                                        {
                                            "type": "input-text",
                                            "label": "价值",
                                            "name": "text",
                                            "size": "",
                                            "mode": "",
                                            "description": "价值多少元，交易时候衡量数量用",
                                            "placeholder": "单位元"
                                        },
                                        {
                                            "type": "textarea",
                                            "label": "描述",
                                            "name": "textarea"
                                        },
                                        {
                                            "type": "input-number",
                                            "label": "份数",
                                            "name": "number-text"
                                        },
                                        {
                                            "type": "input-file",
                                            "label": "编号上传",
                                            "name": "file",
                                            "description": "逗号或者换行符隔开"
                                        }
                                    ],
                                    "api": "",
                                    "mode": "horizontal"
                                }
                            },
                            {
                                label: "首页",
                                url: "index",
                                headerIndex:"1",
                                isDefaultPage:true,
                                schema: {
                                    "interval":0,
                                    "data":{
                                        "items2": [
                                            {
                                                "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                                                "text": "导航1"
                                            },
                                            {
                                                "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                                                "text": "导航2"
                                            },
                                            {
                                                "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                                                "text": "导航3"
                                            },
                                            {
                                                "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                                                "text": "导航4"
                                            }
                                        ]
                                    },
                                    type: "page",
                                    title: "首页",

                                    body: [
                                        {
                                            "type": "carousel",
                                            "auto": false,
                                            "thumbMode": "cover",
                                            "animation": "slide",
                                            "height": 300,
                                            "options": [
                                                {
                                                    "thumbMode": "contain",
                                                    "image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
                                                },
                                                {
                                                    "thumbMode": "contain",
                                                    "image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
                                                },
                                                {
                                                    "thumbMode": "contain",
                                                    "image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg"
                                                }
                                            ]
                                        },
                                        {
                                            "type": "grid-nav",
                                            "source": "${items2}"
                                        },
                                        //卡片页面接口
                                        {
                                            "type": "service",
                                            "schemaApi": {
                                                'initFetch':false,
                                                autoRefresh: false,
                                                method:"get",
                                                "url":"/json/cards.json",
                                                "cache": 2000
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    },
                    {
                        label: "我的",
                        url: "/my",
                        headerIndex:"white",
                        schemaApi:"/json/mysetting.json",
                        children: [
                            {
                                label: "设置",
                                url: "setting",
                                schemaApi:"/json/mysetting/setting.json",
                            }
                        ]
                    },
                    {
                        label: "页面C",
                        schema: {
                            type: "page",
                            title: "页面C",
                            body: "页面C"
                        }
                    },
                    {
                        label: "表单",
                        url: "/form",
                        icon: "fa fa-plus",
                        schemaApi: "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/service/schema?type=form"
                    },
                    {
                        label: "列表",
                        url: "/crud/list",
                        icon: "fa fa-list",
                        schemaApi: "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/service/schema?type=crud"
                    }
                ]
            },
            {
                label: "废弃",
                children: [
                    {
                        label: "首页",
                        schema: {
                            "type": "page",
                            "body": {
                                "type": "card",
                                "href": "https://github.com/baidu/amis",
                                "header": {
                                    "title": "标题",
                                    "subTitle": "副标题",
                                    "description": "这是一段描述",
                                    "avatarText": "AMIS"
                                }
                            }
                        }
                    },
                    {
                        label: "外部链接",
                        link: "http://baidu.gitee.io/amis"
                    },
                    {
                        label: "部门管理",
                        schemaApi: "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/service/form?tpl=tpl3"
                    }
                ]
            }
        ]
    };

    let amis = amisRequire('amis/embed');
    const match = amisRequire('path-to-regexp').match;

    // 如果想用 browserHistory 请切换下这处代码, 其他不用变
    // const history = History.createBrowserHistory();
    const history = History.createHashHistory();


       var $headindex = getHeaderpaths();
       if($headindex === "false"){
           $headindex = 1;
       }
       console.log($headindex);
        let amisInstance = amis.embed(
            '#root',app,
            {
                'data':{
                    'headindex':$headindex,
                    "items":[
                        {
                            "icon": "icon/1.svg",
                            "text": "首页",
                            "clickAction":{
                                "actionType": "link",
                                "link": "/pageA/index",
                                onClick: (e, props) => {

                                    props.data.items[0].icon = "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png";
                                    var abc2 = props.store.updateData({

                                        "items": props.data.items
                                    })

                                }
                            }
                        },
                        {
                            "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                            "text": "市场",
                            "clickAction":{
                                "actionType": "link",
                                "link": "/pageA/1"
                            }
                        },
                        {
                            "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                            "text": "交易",
                            "clickAction":{
                                "type": "button",
                                onClick: (e, props) => {
                                    props.data.items[0].icon = "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png";
                                    var abc2 = props.store.updateData({
                                        "items": props.data.items
                                    })
                                }
                            }
                        },
                        {
                            "icon": "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png",
                            "text": "我的",
                            "clickAction":{
                                "actionType": "link",
                                "link": "/my",
                                onClick: (e, props) => {
                                    props.data.items[0].icon = "https://internal-amis-res.cdn.bcebos.com/images/icon-1.png";
                                    var abc2 = props.store.updateData({
                                        "items": props.data.items
                                    })
                                }
                            }
                        }
                    ]
                },
                location: history.location
            },

            {
                // watchRouteChange: fn => {
                //   return history.listen(fn);
                // },
                requestAdaptor:function(api){
                    return {
                        ...api,
                        headers:{
                            'token':'',
                        }
                    };
                },
                responseAdaptor:function(api, response, query, request){
                    if(response.hasOwnProperty("code")){
                        response.status = response.code;
                        if( response.status == '200'){
                            response.status = '0';
                        }
                    }
                    if(response.hasOwnProperty("result")) {
                        response.data = response.result;
                        response.result = null;
                    }
                    if(response.hasOwnProperty("message")) {
                        response.msg = response.message;
                    }
                    return response;
                },
                updateLocation: (location, replace) => {
                    location = normalizeLink(location);
                    console.log("location", location );
                    if (location === 'goBack') {
                        return history.goBack();
                    } else if (
                        (!/^https?\:\/\//.test(location) &&
                            location ===
                            history.location.pathname + history.location.search) ||
                        location === history.location.href
                    ) {
                        // 目标地址和当前地址一样，不处理，免得重复刷新
                        return;
                    } else if (/^https?\:\/\//.test(location) || !history) {
                        return (window.location.href = location);
                    }

                    history[replace ? 'replace' : 'push'](location);
                },
                jumpTo: (to, action) => {
                    if (to === 'goBack') {
                        return history.goBack();
                    }
                    to = normalizeLink(to);

                    if (isCurrentUrl(to)) {
                        return;
                    }

                    if (action && action.actionType === 'url') {
                        action.blank === false
                            ? (window.location.href = to)
                            : window.open(to, '_blank');
                        return;
                    } else if (action && action.blank) {
                        window.open(to, '_blank');
                        return;
                    }

                    if (/^https?:\/\//.test(to)) {
                        window.location.href = to;
                    } else if (
                        (!/^https?\:\/\//.test(to) &&
                            to === history.pathname + history.location.search) ||
                        to === history.location.href
                    ) {
                        // do nothing
                    } else {
                        history.push(to);
                    }
                },
                isCurrentUrl: isCurrentUrl
               // ,theme: 'sdk'
            }
        );

        history.listen(state => {
            var $headindex = getHeaderpaths(app.pages);
            if($headindex === "false"){
                $headindex = 1;
            }
            amisInstance.getComponentByName("topapp").props.store.updateData({"headindex":$headindex})
            amisInstance.updateProps({
                location: state.location || state
            });
        });















    //解决按键盘弹起的问题
    var winHeight = $(window).height();  //获取当前页面高度
    $(window).resize(function () {
        var thisHeight = $(this).height();
        if ( winHeight - thisHeight > 140 ) {
            //键盘弹出
            $('.cxd-Layout-footer').css('position','static');
        } else {
            //键盘收起
            $('.cxd-Layout-footer').css({'position':'fixed','bottom':'0'});
        }
    })

    //头部收缩
    var targets = document.getElementsByClassName("cxd-Layout-header");
    document.getElementById("root").onscroll=function( event ){
        var height = targets[0].offsetHeight;
        var scrollTop = (event.srcElement ? event.srcElement.scrollTop : false)
            || window.pageYOffset
            || (event.srcElement.body ? event.srcElement.body.scrollTop : 0);
        if(scrollTop>height/2){
            setOpacity( targets[0], 0)
        }else{
            setOpacity( targets[0], 100)
        }
        //console.log(scrollTop);
    }

</script>
</body>
</html>
